package com.mobile.collect.utils;

import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;

import com.mobile.collect.R;

import java.io.File;

import cn.droidlover.xdroidmvp.kit.Kits;
import cn.droidlover.xdroidmvp.kit.NLog;

public class LogRecordUtils {

    public static int ExportLog = 0;//导出日志
    public static int IMPORTLog = 1;//导入日志
    public static int BACKUPTLog = 2;//备份日志

    public void writeRecord(Context context, String message, int logType) {
        NLog.d("writeRecord", message);
        String root = Environment.getExternalStorageDirectory() + "/" + context.getString(R.string.app_name);
        String exportRecordPath = null;
        switch (logType) {
            case 0:
                exportRecordPath = root + File.separator + "日志" + File.separator + "导出日志.txt";
                break;
            case 1:
                exportRecordPath = root + File.separator + "日志" + File.separator + "导入日志.txt";
                break;
            case 2:
                exportRecordPath = root + File.separator + "日志" + File.separator + "备份之日.txt";
                break;
        }
        if (!TextUtils.isEmpty(exportRecordPath)) {
            Kits.File.deleteFile(exportRecordPath);
        }
        Kits.File.writeFile(exportRecordPath, message, true);
    }

    public static void writeTimeRecord(Context context, String method, String message) {
        NLog.d("writeRecord", message);
        String root = Environment.getExternalStorageDirectory() + "/" + context.getString(R.string.app_name);
        String exportRecordPath = null;
        exportRecordPath = root + File.separator + "日志" + File.separator + method + ".txt";
        if (!TextUtils.isEmpty(exportRecordPath)) {
            Kits.File.deleteFile(exportRecordPath);
        }
        Kits.File.writeFile(exportRecordPath, message, true);
    }
}
